package com.ls.nio;

import java.nio.IntBuffer;

public class BasicBuffer {


    public static void main(String[] args) {
        //创建一个Buffer，大小为5，可存放5个int allocate分配
        IntBuffer intBuffer = IntBuffer.allocate(5);
        //capacity 容量
        for (int i = 0; i < intBuffer.capacity(); i++) {
            intBuffer.put(i * 2);
        }

        //将buffer转换，读写切换
        intBuffer.flip();

        while (intBuffer.hasRemaining()){
            System.out.println(intBuffer.get());
        }
    }
}
